import 'dart:convert';

import 'package:example/bean/response_data_entity.dart';
import 'package:example/viewmodel/second_viewmodel.dart';
import 'package:flutter_scaffold/flutter_scaffold.dart';

extension ResponseExt on Response{

  T? check<T>(){
    if(!this.isOk){
      throw this;
    }
    ResponseDataEntity response =  ResponseDataEntity<T>.fromJson(jsonDecode(this.bodyString??""));
    //检查server 返回的业务code
    if(response.errorCode!=0){
      throw ResponseError(response.errorCode, response.errorMSg);
    }
    return response.data;
  }
}